const { resolve } = require('path');
const express = require('express');
const { readFileSync } = require('fs');

const app = express();

app.all('*',(req,res,next) => {
    // 允许的跨域请求
    res.header('Access-Control-Allow-Origin','*');
    // 允许请求的方式。
    res.header('Access-Control-Allow-methods','POST,GET');

    next();
}) 

app.get('/src/asset/img/:filename',(req,res) => {
    res.sendFile(resolve(__dirname,'./src/asset/img/' + req.params.filename));
})

app.get('/getUser',(req, res) => {
    const userData = JSON.parse(readFileSync(resolve(__dirname, './src/data/username.json')));
    res.send(userData);
})

app.listen(8888,function(){
    console.log('welcome to post 8888');
})
